﻿using System.Data;
using System.Collections.Generic;
using System.Linq;
using NaK.Core;
using NaK.Bit.DbObject;

namespace NaK.Bit.Data
{
    public class DatabaseInfo
    {
        public List<string> GetListOfTableNames()
        {
            SqlFast sqlFast = new SqlFast(CommandType.Text);
            DataSet dataSet = sqlFast.GetDataSet("select table_name from information_schema.tables");
            return dataSet.Tables[0].AsEnumerable().Select(column => column[0].ToString()).ToList();
        }
        public List<Table> GetListOfTables()
        {
            SqlFast sqlFast = new SqlFast(CommandType.Text);
            DataSet dataSet = sqlFast.GetDataSet("select * from information_schema.tables");
            List<Table> tables = new List<Table>();
            foreach (DataRow dataRow in dataSet.Tables[0].Rows)
            {
                tables.Add(new Table() { Name = dataRow["table_name"].ToString(), SchemaName = dataRow["table_schema"].ToString(), CatalogName = dataRow["table_catalog"].ToString() });
            }
            return tables;
        }
    }
}
